import 'package:date_format/date_format.dart';

import '../index.dart';

class BaseLeftRightWidget extends StatelessWidget {
  final String title;
  final bool isRequired;
  final bool isHideDivide;
  Widget? rightWidget;

  BaseLeftRightWidget(
      {Key? key,
      this.title = "",
      this.isHideDivide = false,
      this.isRequired = false})
      : super(key: key);

  setRightWidget(Widget? widget) {
    rightWidget = widget;
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> children = <Widget>[];
    if (isRequired) {
      //必填*
      children.add(Text(
        '*',
        style: TextStyle(color: Theme.of(context).colorScheme.error),
      ));
    }
    //标题
    children.add(Text(
      title,
      style: Theme.of(context)
          .textTheme
          .titleMedium
          ?.copyWith(color: Theme.of(context).colorScheme.onSecondary),
    ));

    if (rightWidget != null) {
      children.add(
        Expanded(
          child: rightWidget!,
        ),
      );
    }

    if (!isHideDivide) {
      List<Widget> columnChildren = <Widget>[];
      columnChildren.add(Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: children));
      columnChildren.add(const SizedBox(
        height: 10,
      ));
      columnChildren.add(const Divider(
        height: 1,
      ));

      return Container(
        padding: const EdgeInsets.only(top: 10, left: 16, right: 16),
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.start,
            children: columnChildren),
      );
    } else {
      return Container(
          padding:
              const EdgeInsets.only(top: 10, left: 16, right: 16, bottom: 16),
          child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: children));
    }
  }
}

class BaseUpDownWidget extends StatelessWidget {
  final String title;
  final bool isRequired;
  final bool isHideDivide;
  Widget? downWidget;

  BaseUpDownWidget(
      {Key? key,
      this.title = "",
      this.isHideDivide = false,
      this.isRequired = false})
      : super(key: key);

  setDownWidget(Widget? widget) {
    downWidget = widget;
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> rowChildren = <Widget>[];
    if (isRequired) {
      //必填*
      rowChildren.add(Text(
        '*',
        style: Theme.of(context)
            .textTheme
            .bodyLarge
            ?.copyWith(color: Theme.of(context).colorScheme.error),
      ));
    }
    //标题
    rowChildren.add(Text(
      title,
      style: Theme.of(context)
          .textTheme
          .titleMedium
          ?.copyWith(color: Theme.of(context).colorScheme.onSecondary),
    ));

    List<Widget> columnChildren = <Widget>[];
    columnChildren.add(Row(
      children: rowChildren,
    ));
    columnChildren.add(const SizedBox(
      height: 10,
    ));
    if (downWidget != null) {
      columnChildren.add(
        downWidget!,
      );
    }
    columnChildren.add(const SizedBox(
      height: 10,
    ));
    if (!isHideDivide) {
      columnChildren.add(const Divider(
        height: 1,
      ));
    }

    return Container(
        padding: const EdgeInsets.only(left: 16, right: 16, top: 10),
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: columnChildren));
  }
}
